package display;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;

public class LEDBar_Side extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public static final int LEDBarSize = 4;	

	
Canvas_LEDBar myCanvas;



private static RGBColor barLEDColor[] = new RGBColor[LEDBarSize];
private static RGBColor LEDOnColor[] = new RGBColor[LEDBarSize];
private static RGBColor LEDOffColor[] = new RGBColor[LEDBarSize];


private RGBColor defaultColor = new RGBColor();



public LEDBar_Side()
{
int iCounter;

defaultColor.SetColor(Color.BLACK);

for (iCounter=0;iCounter<barLEDColor.length;iCounter++)
	{
	barLEDColor[iCounter]=defaultColor;
	LEDOnColor[iCounter]=defaultColor;
	LEDOffColor[iCounter]=defaultColor;
	
	}


buildPanel();	
setSize(50,130);
}


private void buildPanel()
{

myCanvas =new Canvas_LEDBar(barLEDColor,Canvas_LEDBar.Orientation.VERTICAL);
	
myCanvas.setLocation(0,0);
myCanvas.setSize(50,130);

add(myCanvas);


	
Timer PeriodicTimer = new Timer(100,new ActionListener()
{
public void actionPerformed(ActionEvent e )
	{
	Repaint();
	}
});	
PeriodicTimer.start();
}




public void Repaint()
{
	myCanvas.paintLEDs(myCanvas.getGraphics());//.repaint();	
//revalidate();	
repaint();	
//this.updateUI();

}




public static void setLEDColor(int index,RGBColor color)
{
	if ((index >=0) && (index <barLEDColor.length))
		{
		barLEDColor[index]=color;
		}
}




public static void setLEDColor(int index,short color)
{
	if ((index >=0) && (index <barLEDColor.length))
		{
		barLEDColor[index]=new RGBColor(color);
		}

}



public static void setLEDStatusColor(int LEDNumber,RGBColor newLEDOnColor,RGBColor newLEDOffColor)
{
	LEDOnColor[LEDNumber]=newLEDOnColor;
	LEDOffColor[LEDNumber]=newLEDOffColor;
}


public static void setLEDS(int LEDPattern)
{
int iCounter;
for (iCounter=0;iCounter<barLEDColor.length;iCounter++)
	{
	if ((LEDPattern & (1<<iCounter))>0)
		{
		barLEDColor[iCounter]=LEDOnColor[iCounter];
		}
	else
		{
		barLEDColor[iCounter]=LEDOffColor[iCounter];		
		}
	}
}

public static void setValue(int newValue)
{
int iCounter;

for (iCounter=0;iCounter<barLEDColor.length;iCounter++)
	{
	if (iCounter<newValue)
		{
		barLEDColor[iCounter]=LEDOnColor[iCounter];
		}
	else
		{
		barLEDColor[iCounter]=LEDOffColor[iCounter];
		}
	}
//TODO Set	
}





}
